//
//  ReadViewController.m
//  项目
//
//  Created by 张诗雨 on 14/12/29.
//  Copyright (c) 2014年 张诗雨. All rights reserved.
//

#import "ReadViewController.h"
#import "WebColor.h"
#import "MusicPlayViewController.h"
@interface ReadViewController ()

@end

@implementation ReadViewController

- (void)dealloc
{
    [_choiceC release];
    [_corpusC release];
    [_sortC release];
    [_segView release];
    [super dealloc];
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.navigationItem.title = @"阅读";
    }
    return self;
}
//创建子视图控制器对象并添加到容器视图控制器上
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [WebColor whiteSmoke];
    self.corpusC = [[CorpusViewController alloc] init];
    [self addChildViewController:_corpusC];
    [self.view addSubview:_corpusC.view];
    [_corpusC release];
    self.sortC = [[SortViewController alloc] init];
    [self addChildViewController:_sortC];
    [self.view addSubview:_sortC.view];
    [_sortC release];
    self.choiceC = [[ChoiceViewController alloc] init];
    [self addChildViewController:_choiceC];
    [self.view addSubview:_choiceC.view];
    [_choiceC release];
    
    [self createTopthreeButton];
    

    
}
- (void)creatItem
{
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    [button addTarget:self action:@selector(leftButtonItemAction:) forControlEvents:UIControlEventTouchUpInside];
    [button setBackgroundImage:[UIImage imageNamed:@"iconfont-ttpodicon.png"] forState:UIControlStateNormal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    [button release];
    
}
- (void)leftButtonItemAction:(id)sender
{
    MusicPlayViewController *musicVC = [[MusicPlayViewController alloc] init];
    [musicVC.tableArray removeAllObjects];
    [self presentViewController:musicVC animated:YES completion:^{
        
    }];
    [musicVC release];
}

//把相应的视图放到最上面
- (void)topChoice
{
    [self.view bringSubviewToFront:self.choiceC.view];
}
- (void)topCorpus
{
    [self.view bringSubviewToFront:_corpusC.view];
}
- (void)topSort
{
    [self.view bringSubviewToFront:self.sortC.view];
}
//创建顶部选项View,控制子视图的层级关系
- (void)createTopthreeButton
{
    NSArray * array = [NSArray arrayWithObjects:@"iconfont-jingxuan.png", @"iconfont-book.png", @"iconfont-fenlei.png", nil];
    self.segView = [[SegmentedView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 45 ) imgNames:array title1:@"精选" title2:@"文集" title3:@"分类"];
    [self.view addSubview:_segView];
    _segView.target = self;
    _segView.action = @selector(topChoice);
    _segView.action1 = @selector(topCorpus);
    _segView.action2 = @selector(topSort);
    _segView.segV1.lable.highlighted = YES;
    
    
    
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
